package com.mall.shopping.dto;

import com.mall.commons.result.AbstractRequest;
import com.mall.commons.tool.exception.ValidateException;
import com.mall.shopping.constants.ShoppingRetCode;
import lombok.Data;

import java.math.BigDecimal;

/**
 * ciggar
 * create-date: 2019/7/24-16:29
 */
@Data
public class AllProductRequest extends AbstractRequest {

    private Integer page;
    private Integer size;
    private String sort;
    private Long cid;
    private String priceGt;
    private String priceLte;

    private String key;

    @Override
    public void requestCheck() {
        if (page <= 0) {
            setPage(1);
        }
        try{
            if (priceGt != null && !"".equals(priceGt)) {
                new BigDecimal(priceGt);
            }
            if (priceLte != null && !"".equals(priceLte)) {
                new BigDecimal(priceLte);
            }
        } catch (Exception e){
            throw new ValidateException(ShoppingRetCode.PARAMETER_VALIDATION_FAILED.getCode(),ShoppingRetCode.PARAMETER_VALIDATION_FAILED.getMessage());
        }
    }
}
